package com.bestcem.xm.award.controller.convert;

import cn.hutool.core.util.StrUtil;
import com.bestcem.xm.award.constant.Constants;
import com.bestcem.xm.award.controller.dto.AwardDTO;
import com.bestcem.xm.award.controller.vo.award.DrawCodeVO;
import com.bestcem.xm.award.controller.vo.award.ImportDrawCodesVO;
import com.bestcem.xm.award.entity.mysql.*;
import com.bestcem.xm.award.entity.pojo.AwardAwardDO;
import com.bestcem.xm.award.enums.DeviceTypeEnum;
import com.bestcem.xm.award.service.bo.award.AwardAwardBO;
import com.bestcem.xm.award.service.dto.FileInfoDTO;
import com.bestcem.xm.award.service.dto.draw.ExportWinnerDetailDTO;
import com.bestcem.xm.award.util.MoneyUtil;
import com.bestcem.xm.common.core.uitls.DateUtil;
import com.bestcem.xm.common.core.uitls.EnumUtil;
import com.bestcem.xm.common.core.uitls.StringUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 奖励转换工具类
 * @author sh.pei <sh.pei@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/18 13:52
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AwardConvert {


    /**
     * AwardAward 转 AwardDTO
     * @param awardAward 数据库数据
     * @return AwardDTO 前端使用DTO
     */
    public static AwardDTO awardAwardToAwardDTO(AwardAwardBO awardAward) {
        if (Objects.isNull(awardAward)) {
            return null;
        }
        AwardDTO awardDTO = new AwardDTO();
        //主键
        awardDTO.setId(awardAward.getId());
        //问卷id
        awardDTO.setProjectId(awardAward.getProjectId());
        //奖励类型
        awardDTO.setType(awardAward.getTType());
        //奖励状态
        awardDTO.setStatus(awardAward.getStatus());
        //机构id
        awardDTO.setOrgId(awardAward.getOrgId());
        //奖励名称
        awardDTO.setName(awardAward.getName());
        //奖励基本配置转换
        if (Objects.nonNull(awardAward.getBasic())) {
            awardDTO.setBasic(basicToAwardBasicDTO(awardAward.getBasic()));
        }
        //奖项配置转换
        if (!CollectionUtils.isEmpty(awardAward.getAwards())) {
            awardAward.getAwards().stream().filter(Objects::nonNull).map(AwardConvert::awardToDrawAwardDTO).forEach(awardDTO::addDrawAward);
        }
        //配送方式转换
        if (Objects.nonNull(awardAward.getIssue())) {
            awardDTO.setIssue(issueToAwardIssueDTO(awardAward.getIssue()));
        }
        //页面配置转换
        if (Objects.nonNull(awardAward.getPage())) {
            awardDTO.setPage(pageToAwardPageDTO(awardAward.getPage()));
        }
        //奖励规则转换
        if (Objects.nonNull(awardAward.getRule())) {
            awardDTO.setRule(ruleToAwardRule(awardAward.getRule()));
        }
        //奖励是否已激活
        if (Objects.nonNull(awardAward.getActivated())) {
            awardDTO.setActivated(awardAward.getActivated());
        }
        //实际领取奖励的数量
        if (Objects.nonNull(awardAward.getCurCount())) {
            awardDTO.setCurrentCount(awardAward.getCurCount());
        }
        //钱包活动id
        if (Objects.nonNull(awardAward.getActivityId())) {
            awardDTO.setActivityId(awardAward.getActivityId());
        }
        //清算标志
        if (Objects.nonNull(awardAward.getSettlement())) {
            awardDTO.setSettlementStatus(awardAward.getSettlement());
        }
        awardDTO.setBaseTime(getBaseTimeDTO(awardAward));
        return awardDTO;
    }

    /**
     * 奖励基本配置转换
     * @param basic 数据库basic数据
     * @return  AwardBasicDTO
     */
    private static AwardDTO.AwardBasicDTO basicToAwardBasicDTO(AwardAwardBO.Basic basic) {
        if (Objects.isNull(basic)) {
            return null;
        }
        AwardDTO.AwardBasicDTO basicDTO = new AwardDTO.AwardBasicDTO();
        // 奖励开始时间
        if (Objects.nonNull(basic.getStartTime())) {
            basicDTO.setStartTime(cn.hutool.core.date.DateUtil.format(DateUtil.getDate(basic.getStartTime()), Constants.DATE_PATTERN));
        }
        // 奖励结束时间
        if (Objects.nonNull(basic.getStopTime())) {
            basicDTO.setEndTime(cn.hutool.core.date.DateUtil.format(DateUtil.getDate(basic.getStopTime()), Constants.DATE_PATTERN));
        }
        //  所有人抽奖次数限制 红包个数
        if (Objects.nonNull(basic.getTotalCount())) {
            basicDTO.setTotalCount(basic.getTotalCount());
        }
        // 红包详情, 会显示在领取红包的入账通知和详情页，比如：问卷红包
        if (Objects.nonNull(basic.getName())) {
            basicDTO.setName(basic.getName());
        }

        // 0: 百分百获得红包; N(>1): 概率红包,预计总参与人数
        if (Objects.nonNull(basic.getProbability())) {
            basicDTO.setProbability(Optional.of(basic.getProbability()).map(Long::intValue).orElse(0));
        }
        // 红包总金额
        if (Objects.nonNull(basic.getTotalAmount())) {
            basicDTO.setTotalAmount(Optional.of(MoneyUtil.yuanToCent(basic.getTotalAmount())).map(Long::intValue).orElse(0));
        }
        // 可选, 单个红包金额, 单位元, 普通红包必选,包含小数、整数、""
        if (Objects.nonNull(basic.getSinAmount())) {
            basicDTO.setSingleAmount(Optional.of(MoneyUtil.yuanToCent(basic.getSinAmount())).map(Long::intValue).orElse(0));
        }
        // 红包页面展示的公司名称
        if (Objects.nonNull(basic.getDisplayName())) {
            basicDTO.setDisplayName(basic.getDisplayName());
        }
        // 红包页面展示的logo
        if (Objects.nonNull(basic.getDisplayLogoPath())) {
            FileInfoDTO fileInfoDTO = new FileInfoDTO();
            // 红包页面展示的logo的id
            if (Objects.nonNull(basic.getDisplayLogoId())) {
                fileInfoDTO.setId(basic.getDisplayLogoId());
            }
            // 红包页面展示的logo的的路径
            if (Objects.nonNull(basic.getDisplayLogoPath())) {
                fileInfoDTO.setUrl(basic.getDisplayLogoPath());
            }
            basicDTO.setDisplayLogo(fileInfoDTO);
        }
        return basicDTO;
    }

    /**
     * 抽奖奖励配置转换
     * @param award 数据库抽奖配置
     * @return DrawAwardDTO
     */
    private static AwardDTO.DrawAwardDTO awardToDrawAwardDTO(AwardAwardBO.Award award) {
        if (Objects.isNull(award)) {
            return null;
        }
        AwardDTO.DrawAwardDTO drawAwardDTO = new AwardDTO.DrawAwardDTO();
        // 奖项等级
        if (Objects.nonNull(award.getLevel())) {
            drawAwardDTO.setLevel(award.getLevel());
        }
        // 奖项名称，列表内唯一
        if (Objects.nonNull(award.getName())) {
            drawAwardDTO.setName(award.getName());
        }
        // 奖项描述
        if (Objects.nonNull(award.getDesc())) {
            drawAwardDTO.setDesc(award.getDesc());
        }
        // 中奖概率
        if (Objects.nonNull(award.getProb())) {
            drawAwardDTO.setProbability(award.getProb().toPlainString());
        }
        // 奖项图片
        if (Objects.nonNull(award.getImg())) {
            drawAwardDTO.setImgUrl(award.getImg());
        }
        // 奖项数量
        if (Objects.nonNull(award.getNum())) {
            drawAwardDTO.setNum(award.getNum());
        }
        // 奖项发放方式
        if (Objects.nonNull(award.getMethod())) {
            drawAwardDTO.setMethod(award.getMethod());
        }
        // 兑奖码前缀
        if (Objects.nonNull(award.getPrefix())) {
            drawAwardDTO.setPrefix(award.getPrefix());
        }
        // 领奖提示
        if (Objects.nonNull(award.getTip())) {
            drawAwardDTO.setTip(award.getTip());
        }
        // 奖项等级描述
        if(Objects.nonNull(award.getLevelStr())) {
            drawAwardDTO.setLevelStr(award.getLevelStr());
        }
        return drawAwardDTO;
    }

    /**
     * 抽奖发放相关信息 转换
     * @param issue 数据库抽奖发放数据
     * @return AwardIssueDTO
     */
    private static AwardDTO.AwardIssueDTO issueToAwardIssueDTO(AwardAwardBO.Issue issue) {
        if (Objects.isNull(issue)) {
            return null;
        }
        AwardDTO.AwardIssueDTO awardIssueDTO = new AwardDTO.AwardIssueDTO();
        // 兑奖操作提示
        if (Objects.nonNull(issue.getTip())) {
            awardIssueDTO.setTip(issue.getTip());
        }
        // 发放方式 @see com.bestcem.xm.award.util.enums.AwardIssueTypeEnum
        if (Objects.nonNull(issue.getMethod())) {
            awardIssueDTO.setType(issue.getMethod());
        }
        // 可选,兑奖码前缀
        if (Objects.nonNull(issue.getPrefix())) {
            awardIssueDTO.setPrefix(issue.getPrefix());
        }
        // 可选,短信通知内容
        if (Objects.nonNull(issue.getSms())) {
            awardIssueDTO.setSmsContent(issue.getSms());
        }
        // 可选,短信模板id
        if (Objects.nonNull(issue.getTemplateId())) {
            awardIssueDTO.setTemplateId(issue.getTemplateId());
        }
        // 可选,短信模板名称
        if (Objects.nonNull(issue.getTemplateTitle())) {
            awardIssueDTO.setTemplateTitle(issue.getTemplateTitle());
        }
        return awardIssueDTO;
    }

    /**
     * 奖项页面配置信息转换
     * @param page 数据库 奖项页面配置
     * @return AwardPageDTO
     */
    private static AwardDTO.AwardPageDTO pageToAwardPageDTO(AwardAwardBO.Page page) {
        if (Objects.isNull(page)) {
            return null;
        }
        AwardDTO.AwardPageDTO awardPageDTO = new AwardDTO.AwardPageDTO();
        // 跳转链接url配置
        if (Objects.nonNull(page.getUrl())) {
            awardPageDTO.setUrl(page.getUrl());
        }
        // 附件列表
        if (!CollectionUtils.isEmpty(page.getAttachments())) {
            page.getAttachments().stream().filter(Objects::nonNull).map(AwardConvert::attachmentToFileInfoDTO).forEach(awardPageDTO::addFileInfo);
        }
        // css自定义代码
        if (Objects.nonNull(page.getGcss())) {
            awardPageDTO.setCssScript(page.getGcss());
        }
        // css自定义代码路径
        if (Objects.nonNull(page.getGcssFp())) {
            awardPageDTO.setCssFilePath(page.getGcssFp());
        }
        // css自定义代码路径id
        if (Objects.nonNull(page.getGcssId())) {
            awardPageDTO.setCssId(page.getGcssId());
        }
        // 奖励页自定义代码
        if (Objects.nonNull(page.getTemplate())) {
            awardPageDTO.setTemplateScript(page.getTemplate());
        }
        // 奖励页自定义代码路径
        if (Objects.nonNull(page.getTemplateFp())) {
            awardPageDTO.setTemplateFilePath(page.getTemplateFp());
        }
        // 奖励页自定义代码路径id
        if (Objects.nonNull(page.getTemplateId())) {
            awardPageDTO.setTemplateId(page.getTemplateId());
        }
        // 手机端页面配置
        if (Objects.nonNull(page.getMobile())) {
            awardPageDTO.setPhone(pageFrontToAwardFrontDTO(page.getMobile()));
        }
        // 电脑端页面配置
        if (Objects.nonNull(page.getPc())) {
            awardPageDTO.setPc(pageFrontToAwardFrontDTO(page.getPc()));
        }
        return awardPageDTO;
    }

    /**
     * 奖项页面附件信息转换
     * @param attachment 数据库 奖项附件配置
     * @return FileInfoDTO
     */
    private static FileInfoDTO attachmentToFileInfoDTO(AwardAwardBO.Attachment attachment) {
        if (Objects.isNull(attachment)) {
            return null;
        }
        FileInfoDTO fileInfoDTO = new FileInfoDTO();
        // 附件名称
        if (Objects.nonNull(attachment.getFileName())) {
            fileInfoDTO.setName(attachment.getFileName());
        }
        // 附件路径
        if (Objects.nonNull(attachment.getFilePath())) {
            fileInfoDTO.setUrl(attachment.getFilePath());
        }
        // 附件id
        if (Objects.nonNull(attachment.getId())) {
            fileInfoDTO.setId(attachment.getId());
        }
        return fileInfoDTO;
    }

    /**
     * 前端页面配置转换
     * @param pageFront 数据库 前端页面配置
     * @return AwardFrontDTO
     */
    private static AwardDTO.AwardFrontDTO pageFrontToAwardFrontDTO(AwardAwardBO.PageFront pageFront) {
        if (Objects.isNull(pageFront)) {
            return null;
        }
        AwardDTO.AwardFrontDTO awardFrontDTO = new AwardDTO.AwardFrontDTO();
        // 前端页面背景配置
        if (Objects.nonNull(pageFront.getBg())) {
            awardFrontDTO.setBackground(pageFrontBgToAwardFrontBgDTO(pageFront.getBg()));
        }
        // 二维码配置
        if (Objects.nonNull(pageFront.getQr())) {
            awardFrontDTO.setQrCode(pageFrontQrToAwardFrontQrDTO(pageFront.getQr()));
        }
        // 中奖提示
        if (Objects.nonNull(pageFront.getTitle())) {
            awardFrontDTO.setTitle(pageFront.getTitle());
        }
        // 结束语内容
        if (Objects.nonNull(pageFront.getText())) {
            awardFrontDTO.setText(pageFrontTextToAwardFrontTxtDTO(pageFront.getText()));
        }
        // logo配置
        if (Objects.nonNull(pageFront.getLogo())) {
            awardFrontDTO.setLogo(pageFrontLogoToAwardFrontLogoDTO(pageFront.getLogo()));
        }
        return awardFrontDTO;
    }

    /**
     * 前端页面背景配置转换
     * @param pageFrontBg 数据库 前端页面背景配置
     * @return  AwardFrontBgDTO
     */
    private static AwardDTO.AwardFrontBgDTO pageFrontBgToAwardFrontBgDTO(AwardAwardBO.PageFrontBg pageFrontBg) {
        if (Objects.isNull(pageFrontBg)) {
            return null;
        }
        AwardDTO.AwardFrontBgDTO awardFrontBgDTO = new AwardDTO.AwardFrontBgDTO();
        // 背景颜色，color与id+path只能二选一，有color就不存储id+path
        if (Objects.nonNull(pageFrontBg.getColor())) {
            awardFrontBgDTO.setColor(pageFrontBg.getColor());
        }
        // 图片id
        if (Objects.nonNull(pageFrontBg.getId())) {
            awardFrontBgDTO.setId(pageFrontBg.getId());
        }
        // 图片路径
        if (Objects.nonNull(pageFrontBg.getPath())) {
            awardFrontBgDTO.setPath(pageFrontBg.getPath());
        }
        return awardFrontBgDTO;
    }

    /**
     * 前端页面二维码配置转换
     * @param pageFrontQr 数据库 前端页面二维码配置
     * @return AwardFrontQrDTO
     */
    private static AwardDTO.AwardFrontQrDTO pageFrontQrToAwardFrontQrDTO(AwardAwardBO.PageFrontQr pageFrontQr) {
        if (Objects.isNull(pageFrontQr)) {
            return null;
        }
        AwardDTO.AwardFrontQrDTO awardFrontQrDTO = new AwardDTO.AwardFrontQrDTO();
        // 图片id
        if (Objects.nonNull(pageFrontQr.getId())) {
            awardFrontQrDTO.setId(pageFrontQr.getId());
        }
        // 图片路径
        if (Objects.nonNull(pageFrontQr.getPath())) {
            awardFrontQrDTO.setPath(pageFrontQr.getPath());
        }
        return awardFrontQrDTO;
    }

    /**
     * 前端页面文字配置转换
     * @param pageFrontText 数据库 前端页面文字配置转换
     * @return AwardFrontTxtDTO
     */
    private static AwardDTO.AwardFrontTxtDTO pageFrontTextToAwardFrontTxtDTO (AwardAwardBO.PageFrontText pageFrontText) {
        if (Objects.isNull(pageFrontText)) {
            return null;
        }
        AwardDTO.AwardFrontTxtDTO awardFrontTxtDTO = new AwardDTO.AwardFrontTxtDTO();
        // 文字颜色
        if (Objects.nonNull(pageFrontText.getColor())) {
            awardFrontTxtDTO.setColor(pageFrontText.getColor());
        }
        // 文本内容
        if (Objects.nonNull(pageFrontText.getData())) {
            awardFrontTxtDTO.setContent(pageFrontText.getData());
        }
        // 是否加粗
        if (Objects.nonNull(pageFrontText.getBold())) {
            awardFrontTxtDTO.setBold(pageFrontText.getBold());
        }
        // 是否倾斜
        if (Objects.nonNull(pageFrontText.getItalic())) {
            awardFrontTxtDTO.setItalic(pageFrontText.getItalic());
        }
        // 是否下划线
        if (Objects.nonNull(pageFrontText.getUnderline())) {
            awardFrontTxtDTO.setUnderline(pageFrontText.getUnderline());
        }
        // 文字大小
        if (Objects.nonNull(pageFrontText.getSize())) {
            awardFrontTxtDTO.setSize(pageFrontText.getSize());
        }
        return awardFrontTxtDTO;
    }

    /**
     * 前端页面logo配置转换
     * @param pageFrontLogo 数据库 前端页面logo配置转换
     * @return AwardFrontLogoDTO
     */
    private static AwardDTO.AwardFrontLogoDTO pageFrontLogoToAwardFrontLogoDTO(AwardAwardBO.PageFrontLogo pageFrontLogo) {
        if (Objects.isNull(pageFrontLogo)) {
            return null;
        }
        AwardDTO.AwardFrontLogoDTO awardFrontLogoDTO = new AwardDTO.AwardFrontLogoDTO();
        // 图片id
        if (Objects.nonNull(pageFrontLogo.getId())) {
            awardFrontLogoDTO.setId(pageFrontLogo.getId());
        }
        // 图片路径
        if (Objects.nonNull(pageFrontLogo.getPath())) {
            awardFrontLogoDTO.setPath(pageFrontLogo.getPath());
        }
        // 缩放比例
        if (Objects.nonNull(pageFrontLogo.getScale())) {
            awardFrontLogoDTO.setScale(pageFrontLogo.getScale());
        }
        // 图片位置
        if (Objects.nonNull(pageFrontLogo.getPos())) {
            awardFrontLogoDTO.setPos(pageFrontLogo.getPos());
        }
        return awardFrontLogoDTO;
    }

    /**
     * 奖励规则配置
     * @param rule 数据库 奖励规则配置
     * @return AwardLimitRuleDTO
     */
    private static AwardDTO.AwardRuleDTO ruleToAwardRule(AwardAwardBO.Rule rule) {
        if (Objects.isNull(rule)) {
            return null;
        }
        AwardDTO.AwardRuleDTO awardRuleDTO = new AwardDTO.AwardRuleDTO();
        // 可选,答题时间限制
        if (Objects.nonNull(rule.getTime())) {
            awardRuleDTO.setTime(rule.getTime());
        }
        // 可选, 单人抽奖次数限制
        if (Objects.nonNull(rule.getDraw())) {
            awardRuleDTO.setDraw(rule.getDraw());
        }
        // 可选,单人中奖次数限制 单微信号领取次数限制
        if (Objects.nonNull(rule.getWin())) {
            awardRuleDTO.setWin(rule.getWin());
        }
        // 可选 账户访问限制
        if (Objects.nonNull(rule.getAccount())) {
            awardRuleDTO.setAccount(rule.getAccount());
        }
        // 可选 设备访问次数限制
        if (Objects.nonNull(rule.getDevice())) {
            awardRuleDTO.setDevice(rule.getDevice());
        }
        // 可选 ip访问次数限制
        if (Objects.nonNull(rule.getIp())) {
            awardRuleDTO.setIp(rule.getIp());
        }
        // 可选，单日领取次数限制
        if (Objects.nonNull(rule.getDay())) {
            awardRuleDTO.setDay(rule.getDay());
        }
        // 可选，奖励结束是否停止投放 is stop deliver
        if (Objects.nonNull(rule.getStopDeliver())) {
            awardRuleDTO.setStopDeliver(rule.getStopDeliver());
        }
        // 可选，设置的问卷分值
        if (Objects.nonNull(rule.getSscore())) {
            awardRuleDTO.setScore(rule.getSscore());
        }
        if (Objects.nonNull(rule.getStopAward())) {
            awardRuleDTO.setStopAward(rule.getStopAward());
        }
        return awardRuleDTO;
    }

    /**
     * 从奖励提取baseModel配置
     * @param awardAward 数据库BaseTime
     * @return BaseTimeDTO
     */
    private static AwardDTO.BaseTimeDTO getBaseTimeDTO(AwardAwardBO awardAward) {
        if (Objects.isNull(awardAward)) {
            return null;
        }
        AwardDTO.BaseTimeDTO baseTimeDTO = new AwardDTO.BaseTimeDTO();
        // 创建时间
        if (Objects.nonNull(awardAward.getCreatedDate())) {
            baseTimeDTO.setCreateTime(cn.hutool.core.date.DateUtil.format(DateUtil.getDate(awardAward.getCreatedDate()), Constants.DATE_PATTERN));
        }
        // 更新时间
        if (Objects.nonNull(awardAward.getUpdatedDate())) {
            baseTimeDTO.setUpdateTime(cn.hutool.core.date.DateUtil.format(DateUtil.getDate(awardAward.getUpdatedDate()), Constants.DATE_PATTERN));
        }
        return baseTimeDTO;
    }

    /**
     * AwardData  转 AwardAward
     * @param awardDTO
     * @return 数据库数据
     */
    public static AwardAwardBO awardDTOToAwardAward(AwardDTO awardDTO) {
        if (Objects.isNull(awardDTO)) {
            return null;
        }
        AwardAwardBO awardAwardBO = new AwardAwardBO();
        //主键
        if (StrUtil.isNotEmpty(awardDTO.getId())) {
            awardAwardBO.setId(awardDTO.getId());
        }
        //问卷id
        if (StrUtil.isNotEmpty(awardDTO.getProjectId())) {
            awardAwardBO.setProjectId(awardDTO.getProjectId());
        }
        //奖励类型
        awardAwardBO.setTType(awardDTO.getType());
        //奖励状态
        awardAwardBO.setStatus(awardDTO.getStatus());
        //机构id
        if (StrUtil.isNotEmpty(awardDTO.getOrgId())) {
            awardAwardBO.setOrgId(awardDTO.getOrgId());
        }
        //奖励名称
        if (StrUtil.isNotEmpty(awardDTO.getName())) {
            awardAwardBO.setName(awardDTO.getName());
        }
        //奖励基本配置转换
        if (Objects.nonNull(awardDTO.getBasic())) {
            awardAwardBO.setBasic(awardBasicDTOToBasic(awardDTO.getBasic()));
        } else {
            awardAwardBO.setBasic(new AwardAwardBO.Basic());
        }
        //奖项配置转换
        if (!CollectionUtils.isEmpty(awardDTO.getDrawAwards())) {
            List<AwardAwardBO.Award> list = awardDTO.getDrawAwards().stream().filter(Objects::nonNull).map(AwardConvert::drawAwardDTOToAward).collect(Collectors.toList());
            awardAwardBO.setAwards(list);
        }
        //配送方式转换
        if (Objects.nonNull(awardDTO.getIssue())) {
            awardAwardBO.setIssue(awardIssueDTOToIssue(awardDTO.getIssue()));
        }
        //页面配置转换
        if (Objects.nonNull(awardDTO.getPage())) {
            awardAwardBO.setPage(awardPageDTOToPage(awardDTO.getPage()));
        }
        //奖励规则转换
        if (Objects.nonNull(awardDTO.getRule())) {
            awardAwardBO.setRule(awardRuleDTOToRule(awardDTO.getRule()));
        }
        return awardAwardBO;
    }

    private static Date localDateTimeToDate(LocalDateTime localDateTime) {
        try {
            ZoneId zoneId = ZoneId.systemDefault();
            ZonedDateTime zdt = localDateTime.atZone(zoneId);
            return Date.from(zdt.toInstant());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 奖励基本配置转换
     * @param awardBasicDTO  basic数据
     * @return  数据库 basic数据
     */
    private static AwardAwardBO.Basic awardBasicDTOToBasic(AwardDTO.AwardBasicDTO awardBasicDTO) {
        if (Objects.isNull(awardBasicDTO)) {
            return null;
        }
        AwardAwardBO.Basic basic = new AwardAwardBO.Basic();
        // 奖励开始时间
        if (Objects.nonNull(awardBasicDTO.getStartTime())) {
            basic.setStartTime(DateUtil.getDate(cn.hutool.core.date.DateUtil.parseDateTime(awardBasicDTO.getStartTime())));
        }
        // 奖励结束时间
        if (Objects.nonNull(awardBasicDTO.getEndTime())) {
            basic.setStopTime(DateUtil.getDate(cn.hutool.core.date.DateUtil.parseDateTime(awardBasicDTO.getEndTime())));
        }
        // 所有人抽奖次数限制 红包个数
        if (awardBasicDTO.getTotalCount() != null && awardBasicDTO.getTotalCount() != 0) {
            basic.setTotalCount(awardBasicDTO.getTotalCount());
        }
        // 红包奖励必传,红包详情, 会显示在领取红包的入账通知和详情页，比如：问卷红包，长度10以内
        basic.setName(awardBasicDTO.getName());
        // 0: 百分百获得红包; N(>1): 概率红包,预计总参与人数;
        if (awardBasicDTO.getProbability() != null) {
            basic.setProbability(Long.valueOf(awardBasicDTO.getProbability()));
        } else {
            basic.setProbability(0L);
        }

        // 可选, 总金额, 单位元, 拼手气红包必选,可能为""
        if (awardBasicDTO.getTotalAmount() != null) {
            basic.setTotalAmount(awardBasicDTO.getTotalAmount() == 0 ? null : MoneyUtil.centToYuan(awardBasicDTO.getTotalAmount()));
        }
        // 可选, 单个红包金额, 单位元, 普通红包必选,包含小数、整数、""
        if (awardBasicDTO.getSingleAmount() != null) {
            basic.setSinAmount(awardBasicDTO.getSingleAmount() == 0 ? null : MoneyUtil.centToYuan(awardBasicDTO.getSingleAmount()));
        }
        // 红包页面展示的公司名称
        basic.setDisplayName(awardBasicDTO.getDisplayName());
        if (Objects.nonNull(awardBasicDTO.getDisplayLogo())) {
            // 红包页面展示的logo的id
            basic.setDisplayLogoId(awardBasicDTO.getDisplayLogo().getId());
            // 红包页面展示的logo的的路径
            basic.setDisplayLogoPath(awardBasicDTO.getDisplayLogo().getUrl());
        }

        return basic;
    }

    /**
     * 抽奖奖励配置转换
     * @param drawAwardDTO 抽奖配置
     * @return 数据库抽奖配置
     */
    private static AwardAwardBO.Award drawAwardDTOToAward(AwardDTO.DrawAwardDTO drawAwardDTO) {
        if (Objects.isNull(drawAwardDTO)) {
            return null;
        }
        AwardAwardBO.Award award = new AwardAwardBO.Award();
        // 奖项等级
        award.setLevel(drawAwardDTO.getLevel());
        // 奖项名称，列表内唯一
        award.setName(drawAwardDTO.getName());
        // 奖项描述
        award.setDesc(drawAwardDTO.getDesc());
        // 中奖概率
        if (StrUtil.isNotEmpty(drawAwardDTO.getProbability())) {
            award.setProb(new BigDecimal(drawAwardDTO.getProbability()));
        }
        // 奖项图片
        award.setImg(drawAwardDTO.getImgUrl());
        // 奖项数量
        if (drawAwardDTO.getNum() != null) {
            award.setNum(drawAwardDTO.getNum() == 0 ? null : drawAwardDTO.getNum());
        }
        // 奖项发放方式
        award.setMethod(drawAwardDTO.getMethod());
        // 奖项兑奖码前缀
        award.setPrefix(drawAwardDTO.getPrefix());
        // 奖项领奖提示
        award.setTip(drawAwardDTO.getTip());
        // 奖项等级描述
        award.setLevelStr(drawAwardDTO.getLevelStr());
        return award;
    }

    /**
     * 抽奖发放相关信息 转换
     * @param awardIssueDTO grpc抽奖发放
     * @return 数据库抽奖发放数据
     */
    private static AwardAwardBO.Issue awardIssueDTOToIssue(AwardDTO.AwardIssueDTO awardIssueDTO) {
        if (Objects.isNull(awardIssueDTO)) {
            return null;
        }
        AwardAwardBO.Issue issue = new AwardAwardBO.Issue();
        // 兑奖操作提示
        issue.setTip(awardIssueDTO.getTip());
        // 发放方式
        issue.setMethod(awardIssueDTO.getType());
        // 可选,兑奖码前缀
        issue.setPrefix(StrUtil.isBlank(awardIssueDTO.getPrefix()) ? null : awardIssueDTO.getPrefix());
        // 可选,短信通知内容
        issue.setSms(StrUtil.isBlank(awardIssueDTO.getSmsContent()) ? null : awardIssueDTO.getSmsContent());
        // 短信模板id
        issue.setTemplateId(StringUtils.isBlank(awardIssueDTO.getTemplateId()) ? null : awardIssueDTO.getTemplateId());
        // 短信模板名称
        issue.setTemplateTitle(StringUtils.isBlank(awardIssueDTO.getTemplateTitle()) ? null : awardIssueDTO.getTemplateTitle());
        return issue;
    }

    /**
     * 奖项页面配置信息转换
     * @param awardPageDTO 奖项页面配置
     * @return 数据库 奖项页面配置
     */
    private static AwardAwardBO.Page awardPageDTOToPage(AwardDTO.AwardPageDTO awardPageDTO) {
        if (Objects.isNull(awardPageDTO)) {
            return null;
        }
        AwardAwardBO.Page page = new AwardAwardBO.Page();
        // 跳转链接url配置
        if (StrUtil.isNotEmpty(awardPageDTO.getUrl())) {
            page.setUrl(awardPageDTO.getUrl());
        }
        // 附件列表
        if (!CollectionUtils.isEmpty(awardPageDTO.getFileInfos())) {
            List<AwardAwardBO.Attachment> list = awardPageDTO.getFileInfos().stream().filter(Objects::nonNull).map(AwardConvert::fileInfoDTOToAttachment).collect(Collectors.toList());
            page.setAttachments(list);
        }
        // css自定义代码
        if (StrUtil.isNotEmpty(awardPageDTO.getCssScript())) {
            page.setGcss(awardPageDTO.getCssScript());
        }
        // css自定义代码路径
        if (StrUtil.isNotEmpty(awardPageDTO.getCssFilePath())) {
            page.setGcssFp(awardPageDTO.getCssFilePath());
        }
        // css自定义代码路径id
        if (StrUtil.isNotEmpty(awardPageDTO.getCssId())) {
            page.setGcssId(awardPageDTO.getCssId());
        }
        // 奖励页自定义代码
        if (StrUtil.isNotEmpty(awardPageDTO.getTemplateScript())) {
            page.setTemplate(awardPageDTO.getTemplateScript());
        }
        // 奖励页自定义代码路径
        if (StrUtil.isNotEmpty(awardPageDTO.getTemplateFilePath())) {
            page.setTemplateFp(awardPageDTO.getTemplateFilePath());
        }
        // 奖励页自定义代码路径id
        if (StrUtil.isNotEmpty(awardPageDTO.getTemplateId())) {
            page.setTemplateId(awardPageDTO.getTemplateId());
        }
        // 手机端页面配置
        if (Objects.nonNull(awardPageDTO.getPhone())) {
            page.setMobile(awardFrontDTOToPageFront(awardPageDTO.getPhone()));
        }
        // 电脑端页面配置
        if (Objects.nonNull(awardPageDTO.getPc())) {
            page.setPc(awardFrontDTOToPageFront(awardPageDTO.getPc()));
        }
        return page;
    }

    /**
     * 奖项页面附件信息转换
     * @param fileInfoDTO 奖项附件配置
     * @return 数据库 奖项附件配置
     */
    private static AwardAwardBO.Attachment fileInfoDTOToAttachment(FileInfoDTO fileInfoDTO) {
        if (Objects.isNull(fileInfoDTO)) {
            return null;
        }
        AwardAwardBO.Attachment attachment = new AwardAwardBO.Attachment();
        // 附件名称
        if (StrUtil.isNotEmpty(fileInfoDTO.getName())) {
            attachment.setFileName(fileInfoDTO.getName());
        }
        // 附件路径
        if (StrUtil.isNotEmpty(fileInfoDTO.getUrl())) {
            attachment.setFilePath(fileInfoDTO.getUrl());
        }
        // 附件id
        if (StrUtil.isNotEmpty(fileInfoDTO.getId())) {
            attachment.setId(fileInfoDTO.getId());
        }
        return attachment;
    }

    /**
     * 前端页面配置转换
     * @param awardFrontDTO grpc 前端页面配置
     * @return 数据库 前端页面配置
     */
    private static AwardAwardBO.PageFront awardFrontDTOToPageFront(AwardDTO.AwardFrontDTO awardFrontDTO) {
        if (Objects.isNull(awardFrontDTO)) {
            return null;
        }
        AwardAwardBO.PageFront pageFront = new AwardAwardBO.PageFront();
        // 前端页面背景配置
        if (Objects.nonNull(awardFrontDTO.getBackground())) {
            pageFront.setBg(awardFrontBgDTOToPageFrontBg(awardFrontDTO.getBackground()));
        }
        // 二维码配置
        if (Objects.nonNull(awardFrontDTO.getQrCode())) {
            pageFront.setQr(awardFrontQrDTOToPageFrontQr(awardFrontDTO.getQrCode()));
        }
        // 中奖提示
        if (Objects.nonNull(awardFrontDTO.getTitle())) {
            pageFront.setTitle(awardFrontDTO.getTitle());
        }
        // 结束语内容 领奖提示
        if (Objects.nonNull(awardFrontDTO.getText())) {
            pageFront.setText(awardFrontTxtDTOToPageFrontText(awardFrontDTO.getText()));
        }
        // logo配置
        if (Objects.nonNull(awardFrontDTO.getLogo())) {
            pageFront.setLogo(awardFrontLogoDTOToPageFrontLogo(awardFrontDTO.getLogo()));
        }
        return pageFront;
    }

    /**
     * 前端页面背景配置转换
     * @param awardFrontBgDTO 前端页面背景配置
     * @return  数据库 前端页面背景配置
     */
    private static AwardAwardBO.PageFrontBg awardFrontBgDTOToPageFrontBg(AwardDTO.AwardFrontBgDTO  awardFrontBgDTO) {
        if (Objects.isNull(awardFrontBgDTO)) {
            return null;
        }
        AwardAwardBO.PageFrontBg pageFrontBg = new AwardAwardBO.PageFrontBg();
        // 背景颜色，color与id+path只能二选一，有color就不存储id+path
        if (StrUtil.isNotEmpty(awardFrontBgDTO.getColor())) {
            pageFrontBg.setColor(awardFrontBgDTO.getColor());
        }
        // 图片id
        if (StrUtil.isNotEmpty(awardFrontBgDTO.getId())) {
            pageFrontBg.setId(awardFrontBgDTO.getId());
        }
        // 图片路径
        if (StrUtil.isNotEmpty(awardFrontBgDTO.getPath())) {
            pageFrontBg.setPath(awardFrontBgDTO.getPath());
        }
        return pageFrontBg;
    }

    /**
     * 前端页面二维码配置转换
     * @param awardFrontQrDTO grpc 前端页面二维码配置
     * @return 数据库 前端页面二维码配置
     */
    private static AwardAwardBO.PageFrontQr awardFrontQrDTOToPageFrontQr(AwardDTO.AwardFrontQrDTO  awardFrontQrDTO) {
        if (Objects.isNull(awardFrontQrDTO)) {
            return null;
        }
        AwardAwardBO.PageFrontQr pageFrontQr = new AwardAwardBO.PageFrontQr();
        // 图片id
        if (StrUtil.isNotEmpty(awardFrontQrDTO.getId())) {
            pageFrontQr.setId(awardFrontQrDTO.getId());
        }
        // 图片路径
        if (StrUtil.isNotEmpty(awardFrontQrDTO.getPath())) {
            pageFrontQr.setPath(awardFrontQrDTO.getPath());
        }
        return pageFrontQr;
    }

    /**
     * 前端页面文字配置转换
     * @param awardFrontTxtDTO 前端页面文字配置转换
     * @return 数据库 前端页面文字配置转换
     */
    private static AwardAwardBO.PageFrontText awardFrontTxtDTOToPageFrontText (AwardDTO.AwardFrontTxtDTO awardFrontTxtDTO) {
        if (Objects.isNull(awardFrontTxtDTO)) {
            return null;
        }
        AwardAwardBO.PageFrontText pageFrontText = new AwardAwardBO.PageFrontText();
        // 文字颜色
        if (StrUtil.isNotEmpty(awardFrontTxtDTO.getColor())) {
            pageFrontText.setColor(awardFrontTxtDTO.getColor());
        }
        // 文本内容
        if (StrUtil.isNotEmpty(awardFrontTxtDTO.getContent())) {
            pageFrontText.setData(awardFrontTxtDTO.getContent());
        }
        // 是否加粗
        pageFrontText.setBold(awardFrontTxtDTO.getBold());
        // 是否倾斜
        pageFrontText.setItalic(awardFrontTxtDTO.getItalic());
        // 是否下划线
        pageFrontText.setUnderline(awardFrontTxtDTO.getUnderline());
        // 文字大小
        pageFrontText.setSize(awardFrontTxtDTO.getSize());
        return pageFrontText;
    }

    /**
     * 前端页面logo配置转换
     * @param awardFrontLogoDTO 前端页面logo配置转换
     * @return 数据库前端页面logo配置转换
     */
    private static AwardAwardBO.PageFrontLogo awardFrontLogoDTOToPageFrontLogo(AwardDTO.AwardFrontLogoDTO awardFrontLogoDTO) {
        if (Objects.isNull(awardFrontLogoDTO)) {
            return null;
        }
        AwardAwardBO.PageFrontLogo pageFrontLogo = new AwardAwardBO.PageFrontLogo();
        // 图片id
        if (StrUtil.isNotEmpty(awardFrontLogoDTO.getId())) {
            pageFrontLogo.setId(awardFrontLogoDTO.getId());
        }
        // 图片路径
        if (StrUtil.isNotEmpty(awardFrontLogoDTO.getPath())) {
            pageFrontLogo.setPath(awardFrontLogoDTO.getPath());
        }
        // 缩放比例
        pageFrontLogo.setScale(awardFrontLogoDTO.getScale());
        // 图片位置
        pageFrontLogo.setPos(awardFrontLogoDTO.getPos());

        return pageFrontLogo;
    }

    /**
     * 奖励规则配置
     * @param awardRuleDTO 奖励规则配置
     * @return  数据库 奖励规则配置
     */
    private static AwardAwardBO.Rule awardRuleDTOToRule(AwardDTO.AwardRuleDTO awardRuleDTO) {
        if (Objects.isNull(awardRuleDTO)) {
            return null;
        }
        AwardAwardBO.Rule rule = new AwardAwardBO.Rule();
        // 可选,答题时间限制
        if (awardRuleDTO.getTime() != null) {
            rule.setTime(awardRuleDTO.getTime() == 0 ? null : awardRuleDTO.getTime());
        }
        // 单人抽奖次数限制
        if (awardRuleDTO.getDraw() != null) {
            rule.setDraw(awardRuleDTO.getDraw() == 0 ? null : awardRuleDTO.getDraw());
        }
        // 单人中奖次数限制 单微信号领取次数限制
        if (awardRuleDTO.getWin() != null) {
            rule.setWin(awardRuleDTO.getWin() == 0 ? null : awardRuleDTO.getWin());
        }
        // 账户访问限制
        if (awardRuleDTO.getAccount() != null) {
            rule.setAccount(awardRuleDTO.getAccount() == 0 ? null : awardRuleDTO.getAccount());
        }
        // 设备访问次数限制
        if (awardRuleDTO.getDevice() != null) {
            rule.setDevice(awardRuleDTO.getDevice() == 0 ? null : awardRuleDTO.getDevice());
        }
        // 单日领取次数限制
        if (awardRuleDTO.getIp() != null) {
            rule.setIp(awardRuleDTO.getIp() == 0 ? null : awardRuleDTO.getIp());
        }
        // 单日领取次数限制
        if (awardRuleDTO.getDay() != null) {
            rule.setDay(awardRuleDTO.getDay() == 0 ? null : awardRuleDTO.getDay());
        }
        // 奖励结束是否停止投放 is stop deliver
        if (awardRuleDTO.getStopDeliver() != null) {
            rule.setStopDeliver(awardRuleDTO.getStopDeliver());
        }
        // 设置的问卷分值
        if (awardRuleDTO.getScore() != null) {
            rule.setSscore(awardRuleDTO.getScore() == 0 ? null : awardRuleDTO.getScore());
        }
        // 有效期内达到抽奖次数是否结束奖励
        if (awardRuleDTO.getStopAward() != null) {
            rule.setStopAward(awardRuleDTO.getStopAward());
        }
        return rule;
    }

    /**
     * 兑奖码导入 DTO转VO
     *
     * @param list 兑奖码数据列表
     * @return 兑奖码信息
     * @author jie.yao <jie.yao@idiaoyan.com>
     * @date 2021/8/18 17:50
     */
    public static ImportDrawCodesVO importDrawCodesConversion(List<ExportWinnerDetailDTO> list) {
        List<DrawCodeVO> drawCodeVOList = list.stream().map(dto -> {
            DrawCodeVO vo = new DrawCodeVO();
            vo.setCode(StringUtil.strTrim(dto.getCode()));
            vo.setLevel(StringUtil.strTrim(dto.getLevel()));
            vo.setName(StringUtil.strTrim(dto.getName()));
            return vo;
        }).collect(Collectors.toList());
        ImportDrawCodesVO importDrawCodesVO = new ImportDrawCodesVO();
        importDrawCodesVO.setWins(drawCodeVOList);
        return importDrawCodesVO;
    }

    /**
     * service层与controller层转换
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardBO awardAwardDOToAwardAwardBO(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null) {
            return null;
        }
        AwardAwardBO awardAwardBO = new AwardAwardBO();
        awardAwardBO.setId(awardAwardDO.getId());
        awardAwardBO.setRecordFlag(awardAwardDO.getRecordFlag());
        awardAwardBO.setCreatedDate(awardAwardDO.getCreatedDate());
        awardAwardBO.setCreatedId(awardAwardDO.getCreatedId());
        awardAwardBO.setUpdatedDate(awardAwardDO.getUpdatedDate());
        awardAwardBO.setUpdatedId(awardAwardDO.getUpdatedId());
        awardAwardBO.setProjectId(awardAwardDO.getProjectId());
        awardAwardBO.setTType(awardAwardDO.getTType());
        awardAwardBO.setStatus(awardAwardDO.getStatus());
        awardAwardBO.setOrgId(awardAwardDO.getOrgId());
        awardAwardBO.setName(awardAwardDO.getName());
        awardAwardBO.setActivated(awardAwardDO.getActivated());
        awardAwardBO.setCurCount(awardAwardDO.getCurCount());
        awardAwardBO.setActivityId(awardAwardDO.getActivityId());
        awardAwardBO.setSettlement(awardAwardDO.getSettlement());

        // 奖励基本配置
        if (awardAwardDO.getBasic() != null) {
            AwardAwardDO.Basic basic = awardAwardDO.getBasic();
            AwardAwardBO.Basic newBasic = new AwardAwardBO.Basic();
            newBasic.setStartTime(basic.getStartTime());
            newBasic.setStopTime(basic.getStopTime());
            newBasic.setTotalCount(basic.getTotalCount());
            newBasic.setName(basic.getName());
            newBasic.setProbability(basic.getProbability());
            newBasic.setTotalAmount(basic.getTotalAmount());
            newBasic.setSinAmount(basic.getSinAmount());
            newBasic.setDisplayName(basic.getDisplayName());
            newBasic.setDisplayLogoId(basic.getDisplayLogoId());
            newBasic.setDisplayLogoPath(basic.getDisplayLogoPath());
            awardAwardBO.setBasic(newBasic);
        }
        // 抽奖奖项列表
        if (!CollectionUtils.isEmpty(awardAwardDO.getAwards())) {
            List<AwardAwardBO.Award> awards = new ArrayList<>();
            for (AwardAwardDO.Award award : awardAwardDO.getAwards()) {
                AwardAwardBO.Award newAward = new AwardAwardBO.Award();
                newAward.setLevel(award.getLevel());
                newAward.setName(award.getName());
                newAward.setDesc(award.getDesc());
                newAward.setProb(award.getProb());
                newAward.setImg(award.getImg());
                newAward.setNum(award.getNum());
                newAward.setMethod(award.getMethod());
                newAward.setPrefix(award.getPrefix());
                newAward.setTip(award.getTip());
                newAward.setLevelStr(award.getLevelStr());
                awards.add(newAward);
            }

            awardAwardBO.setAwards(awards);
        }
        // 抽奖发放相关信息
        if (awardAwardDO.getIssue() != null) {
            AwardAwardDO.Issue issue = awardAwardDO.getIssue();
            AwardAwardBO.Issue newIssue = new AwardAwardBO.Issue();
            newIssue.setTip(issue.getTip());
            newIssue.setMethod(issue.getMethod());
            newIssue.setPrefix(issue.getPrefix());
            newIssue.setSms(issue.getSms());
            newIssue.setTemplateId(issue.getTemplateId());
            newIssue.setTemplateTitle(issue.getTemplateTitle());

            awardAwardBO.setIssue(newIssue);
        }
        // 页面配置
        if (awardAwardDO.getPage() != null) {
            AwardAwardDO.Page page = awardAwardDO.getPage();
            AwardAwardBO.Page newPage = new AwardAwardBO.Page();
            newPage.setUrl(page.getUrl());
            newPage.setGcss(page.getGcss());
            newPage.setGcssFp(page.getGcssFp());
            newPage.setGcssId(page.getGcssId());
            newPage.setTemplate(page.getTemplate());
            newPage.setTemplateFp(page.getTemplateFp());
            newPage.setTemplateId(page.getTemplateId());
            // 附件列表
            if (!CollectionUtils.isEmpty(page.getAttachments())) {
                List<AwardAwardBO.Attachment> attachmentList = new ArrayList<>();
                for (AwardAwardDO.Attachment attachment : page.getAttachments()) {
                    AwardAwardBO.Attachment newAttachment = new AwardAwardBO.Attachment();
                    newAttachment.setFileName(attachment.getFileName());
                    newAttachment.setFilePath(attachment.getFilePath());
                    newAttachment.setId(attachment.getId());
                    newAttachment.setUpdateTime(attachment.getUpdateTime());

                    attachmentList.add(newAttachment);
                }
                newPage.setAttachments(attachmentList);
            }
            // 手机端页面配置
            if (page.getMobile() != null) {
                newPage.setMobile(awardAwardDOPageFrontToAwardAwardBOPageFront(page.getMobile()));
            }
            // 电脑端页面配置
            if (page.getPc() != null) {
                newPage.setPc(awardAwardDOPageFrontToAwardAwardBOPageFront(page.getPc()));
            }
            awardAwardBO.setPage(newPage);
        }
        // 限制规则
        if (awardAwardDO.getRule() != null) {
            AwardAwardDO.Rule rule = awardAwardDO.getRule();
            AwardAwardBO.Rule newRule = new AwardAwardBO.Rule();
            newRule.setTime(rule.getTime());
            newRule.setDraw(rule.getDraw());
            newRule.setWin(rule.getWin());
            newRule.setAccount(rule.getAccount());
            newRule.setDevice(rule.getDevice());
            newRule.setIp(rule.getIp());
            newRule.setDay(rule.getDay());
            newRule.setStopDeliver(rule.getStopDeliver());
            newRule.setSscore(rule.getSscore());
            newRule.setStopAward(rule.getStopAward());

            awardAwardBO.setRule(newRule);
        }
        // 积分奖励配置
        if (awardAwardDO.getBandPoint() != null) {
            AwardAwardDO.BandPoint bandPoint = awardAwardDO.getBandPoint();
            AwardAwardBO.BandPoint newBandPoint = new AwardAwardBO.BandPoint();
            newBandPoint.setSinPoint(bandPoint.getSinPoint());
            newBandPoint.setPointId(bandPoint.getPointId());
            newBandPoint.setCode(bandPoint.getCode());
            newBandPoint.setPointName(bandPoint.getPointName());
            newBandPoint.setRemark(bandPoint.getRemark());
            newBandPoint.setTotal(bandPoint.getTotal());
            newBandPoint.setStopAdvance(bandPoint.getStopAdvance());
            newBandPoint.setTip(bandPoint.getTip());

            awardAwardBO.setBandPoint(newBandPoint);
        }

        return awardAwardBO;
    }

    /**
     * 前端页面配置转换
     * @param pageFront
     * @return
     */
    private static AwardAwardBO.PageFront awardAwardDOPageFrontToAwardAwardBOPageFront(AwardAwardDO.PageFront pageFront) {
        if (pageFront == null) {
            return null;
        }
        AwardAwardBO.PageFront newPageFront = new AwardAwardBO.PageFront();
        newPageFront.setTitle(pageFront.getTitle());
        // 前端页面背景配置
        if (pageFront.getBg() != null) {
            AwardAwardDO.PageFrontBg bg = pageFront.getBg();
            AwardAwardBO.PageFrontBg newBg = new AwardAwardBO.PageFrontBg();
            newBg.setColor(bg.getColor());
            newBg.setId(bg.getId());
            newBg.setPath(bg.getPath());

            newPageFront.setBg(newBg);
        }
        // 二维码配置
        if (pageFront.getQr() != null) {
            AwardAwardDO.PageFrontQr qr = pageFront.getQr();
            AwardAwardBO.PageFrontQr newQr = new AwardAwardBO.PageFrontQr();
            newQr.setId(qr.getId());
            newQr.setPath(qr.getPath());

            newPageFront.setQr(newQr);
        }
        // 结束语内容， 领奖提示
        if (pageFront.getText() != null) {
            AwardAwardDO.PageFrontText text = pageFront.getText();
            AwardAwardBO.PageFrontText newText = new AwardAwardBO.PageFrontText();
            newText.setData(text.getData());

            newPageFront.setText(newText);
        }
        // logo信息
        if (pageFront.getLogo() != null) {
            AwardAwardDO.PageFrontLogo logo = pageFront.getLogo();
            AwardAwardBO.PageFrontLogo newLogo = new AwardAwardBO.PageFrontLogo();
            newLogo.setId(logo.getId());
            newLogo.setPath(logo.getPath());
            newLogo.setScale(logo.getScale());
            newLogo.setPos(logo.getPos());

            newPageFront.setLogo(newLogo);
        }
        return newPageFront;
    }

    /**
     * service层与controller层转换
     * @param awardAwardBO
     * @return
     */
    public static AwardAwardDO awardAwardBOToAwardAwardDO(AwardAwardBO awardAwardBO) {
        if (awardAwardBO == null) {
            return null;
        }
        AwardAwardDO awardAwardDO = new AwardAwardDO();
        awardAwardDO.setId(awardAwardBO.getId());
        awardAwardDO.setRecordFlag(awardAwardBO.getRecordFlag());
        awardAwardDO.setCreatedDate(awardAwardBO.getCreatedDate());
        awardAwardDO.setCreatedId(awardAwardBO.getCreatedId());
        awardAwardDO.setUpdatedDate(awardAwardBO.getUpdatedDate());
        awardAwardDO.setUpdatedId(awardAwardBO.getUpdatedId());
        awardAwardDO.setProjectId(awardAwardBO.getProjectId());
        awardAwardDO.setTType(awardAwardBO.getTType());
        awardAwardDO.setStatus(awardAwardBO.getStatus());
        awardAwardDO.setOrgId(awardAwardBO.getOrgId());
        awardAwardDO.setName(awardAwardBO.getName());
        awardAwardDO.setActivated(awardAwardBO.getActivated());
        awardAwardDO.setCurCount(awardAwardBO.getCurCount());
        awardAwardDO.setActivityId(awardAwardBO.getActivityId());
        awardAwardDO.setSettlement(awardAwardBO.getSettlement());

        // 奖励基本配置
        if (awardAwardBO.getBasic() != null) {
            AwardAwardBO.Basic basic = awardAwardBO.getBasic();
            AwardAwardDO.Basic newBasic = new AwardAwardDO.Basic();
            newBasic.setStartTime(basic.getStartTime());
            newBasic.setStopTime(basic.getStopTime());
            newBasic.setTotalCount(basic.getTotalCount());
            newBasic.setName(basic.getName());
            newBasic.setProbability(basic.getProbability());
            newBasic.setTotalAmount(basic.getTotalAmount());
            newBasic.setSinAmount(basic.getSinAmount());
            newBasic.setDisplayName(basic.getDisplayName());
            newBasic.setDisplayLogoId(basic.getDisplayLogoId());
            newBasic.setDisplayLogoPath(basic.getDisplayLogoPath());
            awardAwardDO.setBasic(newBasic);
        }
        // 抽奖奖项列表
        if (!CollectionUtils.isEmpty(awardAwardBO.getAwards())) {
            List<AwardAwardDO.Award> awards = new ArrayList<>();
            for (AwardAwardBO.Award award : awardAwardBO.getAwards()) {
                AwardAwardDO.Award newAward = new AwardAwardDO.Award();
                newAward.setLevel(award.getLevel());
                newAward.setName(award.getName());
                newAward.setDesc(award.getDesc());
                newAward.setProb(award.getProb());
                newAward.setImg(award.getImg());
                newAward.setNum(award.getNum());
                newAward.setMethod(award.getMethod());
                newAward.setPrefix(award.getPrefix());
                newAward.setTip(award.getTip());
                newAward.setLevelStr(award.getLevelStr());
                awards.add(newAward);
            }

            awardAwardDO.setAwards(awards);
        }
        // 抽奖发放相关信息
        if (awardAwardBO.getIssue() != null) {
            AwardAwardBO.Issue issue = awardAwardBO.getIssue();
            AwardAwardDO.Issue newIssue = new AwardAwardDO.Issue();
            newIssue.setTip(issue.getTip());
            newIssue.setMethod(issue.getMethod());
            newIssue.setPrefix(issue.getPrefix());
            newIssue.setSms(issue.getSms());
            newIssue.setTemplateId(issue.getTemplateId());
            newIssue.setTemplateTitle(issue.getTemplateTitle());

            awardAwardDO.setIssue(newIssue);
        }
        // 页面配置
        if (awardAwardBO.getPage() != null) {
            AwardAwardBO.Page page = awardAwardBO.getPage();
            AwardAwardDO.Page newPage = new AwardAwardDO.Page();
            newPage.setUrl(page.getUrl());
            newPage.setGcss(page.getGcss());
            newPage.setGcssFp(page.getGcssFp());
            newPage.setGcssId(page.getGcssId());
            newPage.setTemplate(page.getTemplate());
            newPage.setTemplateFp(page.getTemplateFp());
            newPage.setTemplateId(page.getTemplateId());
            // 附件列表
            if (!CollectionUtils.isEmpty(page.getAttachments())) {
                List<AwardAwardDO.Attachment> attachmentList = new ArrayList<>();
                for (AwardAwardBO.Attachment attachment : page.getAttachments()) {
                    AwardAwardDO.Attachment newAttachment = new AwardAwardDO.Attachment();
                    newAttachment.setFileName(attachment.getFileName());
                    newAttachment.setFilePath(attachment.getFilePath());
                    newAttachment.setId(attachment.getId());
                    newAttachment.setUpdateTime(attachment.getUpdateTime());

                    attachmentList.add(newAttachment);
                }
                newPage.setAttachments(attachmentList);
            }
            // 手机端页面配置
            if (page.getMobile() != null) {
                newPage.setMobile(awardAwardBOPageFrontToAwardAwardDOPageFront(page.getMobile()));
            }
            // 电脑端页面配置
            if (page.getPc() != null) {
                newPage.setPc(awardAwardBOPageFrontToAwardAwardDOPageFront(page.getPc()));
            }
            awardAwardDO.setPage(newPage);
        }
        // 限制规则
        if (awardAwardBO.getRule() != null) {
            AwardAwardBO.Rule rule = awardAwardBO.getRule();
            AwardAwardDO.Rule newRule = new AwardAwardDO.Rule();
            newRule.setTime(rule.getTime());
            newRule.setDraw(rule.getDraw());
            newRule.setWin(rule.getWin());
            newRule.setAccount(rule.getAccount());
            newRule.setDevice(rule.getDevice());
            newRule.setIp(rule.getIp());
            newRule.setDay(rule.getDay());
            newRule.setStopDeliver(rule.getStopDeliver());
            newRule.setSscore(rule.getSscore());
            newRule.setStopAward(rule.getStopAward());

            awardAwardDO.setRule(newRule);
        }
        // 积分奖励配置
        if (awardAwardBO.getBandPoint() != null) {
            AwardAwardBO.BandPoint bandPoint = awardAwardBO.getBandPoint();
            AwardAwardDO.BandPoint newBandPoint = new AwardAwardDO.BandPoint();
            newBandPoint.setSinPoint(bandPoint.getSinPoint());
            newBandPoint.setPointId(bandPoint.getPointId());
            newBandPoint.setCode(bandPoint.getCode());
            newBandPoint.setPointName(bandPoint.getPointName());
            newBandPoint.setRemark(bandPoint.getRemark());
            newBandPoint.setTotal(bandPoint.getTotal());
            newBandPoint.setStopAdvance(bandPoint.getStopAdvance());
            newBandPoint.setTip(bandPoint.getTip());

            awardAwardDO.setBandPoint(newBandPoint);
        }

        return awardAwardDO;
    }

    /**
     * 前端页面配置转换
     * @param pageFront
     * @return
     */
    private static AwardAwardDO.PageFront awardAwardBOPageFrontToAwardAwardDOPageFront(AwardAwardBO.PageFront pageFront) {
        if (pageFront == null) {
            return null;
        }
        AwardAwardDO.PageFront newPageFront = new AwardAwardDO.PageFront();
        newPageFront.setTitle(pageFront.getTitle());
        // 前端页面背景配置
        if (pageFront.getBg() != null) {
            AwardAwardBO.PageFrontBg bg = pageFront.getBg();
            AwardAwardDO.PageFrontBg newBg = new AwardAwardDO.PageFrontBg();
            newBg.setColor(bg.getColor());
            newBg.setId(bg.getId());
            newBg.setPath(bg.getPath());

            newPageFront.setBg(newBg);
        }
        // 二维码配置
        if (pageFront.getQr() != null) {
            AwardAwardBO.PageFrontQr qr = pageFront.getQr();
            AwardAwardDO.PageFrontQr newQr = new AwardAwardDO.PageFrontQr();
            newQr.setId(qr.getId());
            newQr.setPath(qr.getPath());

            newPageFront.setQr(newQr);
        }
        // 结束语内容， 领奖提示
        if (pageFront.getText() != null) {
            AwardAwardBO.PageFrontText text = pageFront.getText();
            AwardAwardDO.PageFrontText newText = new AwardAwardDO.PageFrontText();
            newText.setData(text.getData());

            newPageFront.setText(newText);
        }
        // logo信息
        if (pageFront.getLogo() != null) {
            AwardAwardBO.PageFrontLogo logo = pageFront.getLogo();
            AwardAwardDO.PageFrontLogo newLogo = new AwardAwardDO.PageFrontLogo();
            newLogo.setId(logo.getId());
            newLogo.setPath(logo.getPath());
            newLogo.setScale(logo.getScale());
            newLogo.setPos(logo.getPos());

            newPageFront.setLogo(newLogo);
        }
        return newPageFront;
    }

    /**
     * dao层DO转mysql实体 奖励基本信息
     *
     * @param awardAwardDO
     * @return
     */
    public static AwardEntity awardAwardDOToAwardEntity(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null) {
            return null;
        }
        AwardEntity awardEntity = new AwardEntity();
        awardEntity.setAwardId(awardAwardDO.getId());
        awardEntity.setOrgId(awardAwardDO.getOrgId());
        awardEntity.setProjectId(awardAwardDO.getProjectId());
        awardEntity.setType(awardAwardDO.getTType());
        awardEntity.setStatus(awardAwardDO.getStatus());
        awardEntity.setName(awardAwardDO.getName());
        awardEntity.setActivated(EnumUtil.booleanToInt(awardAwardDO.getActivated()));
        awardEntity.setCurrentCount(awardAwardDO.getCurCount());
        if (awardAwardDO.getBasic() != null) {
            awardEntity.setStartTime(awardAwardDO.getBasic().getStartTime());
            awardEntity.setEndTime(awardAwardDO.getBasic().getStopTime());
        }
        awardEntity.setCreatorId(awardAwardDO.getCreatedId());
        awardEntity.setOperatorId(awardAwardDO.getUpdatedId());
        awardEntity.setCreateTime(awardAwardDO.getCreatedDate());
        awardEntity.setUpdateTime(awardAwardDO.getUpdatedDate());
        return awardEntity;
    }

    /**
     * dao层mysql实体转DO 奖励基本信息
     *
     * @param awardEntity
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardEntityToAwardAwardDO(AwardEntity awardEntity, AwardAwardDO awardAwardDO) {
        if (awardEntity == null) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(awardEntity.getAwardId());
        awardAwardDO.setOrgId(awardEntity.getOrgId());
        awardAwardDO.setProjectId(awardEntity.getProjectId());
        awardAwardDO.setTType(awardEntity.getType());
        awardAwardDO.setStatus(awardEntity.getStatus());
        awardAwardDO.setName(awardEntity.getName());
        awardAwardDO.setActivated(EnumUtil.intToBoolean(awardEntity.getActivated()));
        awardAwardDO.setCurCount(awardEntity.getCurrentCount());
        if (awardEntity.getStartTime() != null || awardEntity.getEndTime() != null) {
            AwardAwardDO.Basic basic = awardAwardDO.getBasic();
            if (basic == null) {
                basic = new AwardAwardDO.Basic();
            }
            basic.setStartTime(awardEntity.getStartTime());
            basic.setStopTime(awardEntity.getEndTime());

            awardAwardDO.setBasic(basic);
        }
        awardAwardDO.setRecordFlag(awardEntity.getRecordFlag());
        awardAwardDO.setCreatedId(awardEntity.getCreatorId());
        awardAwardDO.setUpdatedId(awardEntity.getOperatorId());
        awardAwardDO.setCreatedDate(awardEntity.getCreateTime());
        awardAwardDO.setUpdatedDate(awardEntity.getUpdateTime());
        return awardAwardDO;
    }

    /**
     *  dao层DO转mysql实体 积分奖励信息
     *
     * @param awardAwardDO
     * @return
     */
    public static AwardBandPointEntity awardAwardDOToAwardBandPointEntity(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null || awardAwardDO.getBandPoint() == null) {
            return null;
        }
        AwardAwardDO.BandPoint bandPoint = awardAwardDO.getBandPoint();
        AwardBandPointEntity awardBandPointEntity = new AwardBandPointEntity();
        awardBandPointEntity.setAwardId(awardAwardDO.getId());
        awardBandPointEntity.setSinglePoint(bandPoint.getSinPoint());
        awardBandPointEntity.setPointId(bandPoint.getPointId());
        awardBandPointEntity.setPointCode(bandPoint.getCode());
        awardBandPointEntity.setPointName(bandPoint.getPointName());
        awardBandPointEntity.setRemark(bandPoint.getRemark());
        awardBandPointEntity.setTotal(bandPoint.getTotal());
        awardBandPointEntity.setStopAdvance(EnumUtil.booleanToInt(bandPoint.getStopAdvance()));
        awardBandPointEntity.setTip(bandPoint.getTip());
        if (awardAwardDO.getBasic() != null) {
            AwardAwardDO.Basic basic = awardAwardDO.getBasic();
            awardBandPointEntity.setDisplayName(basic.getDisplayName());
            awardBandPointEntity.setDisplayLogoId(basic.getDisplayLogoId());
            awardBandPointEntity.setDisplayLogoPath(basic.getDisplayLogoPath());
        }
        return awardBandPointEntity;
    }

    /**
     * dao层mysql实体转DO 积分奖励信息
     *
     * @param awardBandPointEntity
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardBandPointEntityToAwardAwardDO(AwardBandPointEntity awardBandPointEntity, AwardAwardDO awardAwardDO) {
        if (awardBandPointEntity == null) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(awardBandPointEntity.getAwardId());
        AwardAwardDO.BandPoint bandPoint = new AwardAwardDO.BandPoint();
        bandPoint.setSinPoint(awardBandPointEntity.getSinglePoint());
        bandPoint.setPointId(awardBandPointEntity.getPointId());
        bandPoint.setCode(awardBandPointEntity.getPointCode());
        bandPoint.setPointName(awardBandPointEntity.getPointName());
        bandPoint.setRemark(awardBandPointEntity.getRemark());
        bandPoint.setTotal(awardBandPointEntity.getTotal());
        bandPoint.setStopAdvance(EnumUtil.intToBoolean(awardBandPointEntity.getStopAdvance()));
        bandPoint.setTip(awardBandPointEntity.getTip());
        awardAwardDO.setBandPoint(bandPoint);

        AwardAwardDO.Basic basic = awardAwardDO.getBasic();
        basic.setDisplayName(awardBandPointEntity.getDisplayName());
        basic.setDisplayLogoId(awardBandPointEntity.getDisplayLogoId());
        basic.setDisplayLogoPath(awardBandPointEntity.getDisplayLogoPath());
        awardAwardDO.setBasic(basic);
        return awardAwardDO;
    }

    /**
     *  dao层DO转mysql实体 定制奖励信息
     *
     * @param awardAwardDO
     * @return
     */
    public static AwardCustomEntity awardAwardDOToAwardCustomEntity(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null || awardAwardDO.getPage() == null) {
            return null;
        }
        AwardCustomEntity awardCustomEntity = new AwardCustomEntity();
        awardCustomEntity.setAwardId(awardAwardDO.getId());

        AwardAwardDO.Page page = awardAwardDO.getPage();
        awardCustomEntity.setUrl(page.getUrl());
        awardCustomEntity.setCssScript(page.getGcss());
        awardCustomEntity.setCssFilePath(page.getGcssFp());
        awardCustomEntity.setCssId(page.getGcssId());
        awardCustomEntity.setTemplateScript(page.getTemplate());
        awardCustomEntity.setTemplateFilePath(page.getTemplateFp());
        awardCustomEntity.setTemplateId(page.getTemplateId());
        return awardCustomEntity;
    }

    /**
     * dao层mysql实体转DO 定制奖励信息
     *
     * @param awardCustomEntity
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardCustomEntityToAwardAwardDO(AwardCustomEntity awardCustomEntity, AwardAwardDO awardAwardDO) {
        if (awardCustomEntity == null) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(awardCustomEntity.getAwardId());
        AwardAwardDO.Page page = new AwardAwardDO.Page();
        page.setUrl(awardCustomEntity.getUrl());
        page.setGcss(awardCustomEntity.getCssScript());
        page.setGcssFp(awardCustomEntity.getCssFilePath());
        page.setGcssId(awardCustomEntity.getCssId());
        page.setTemplate(awardCustomEntity.getTemplateScript());
        page.setTemplateFp(awardCustomEntity.getTemplateFilePath());
        page.setTemplateId(awardCustomEntity.getTemplateId());
        awardAwardDO.setPage(page);
        return awardAwardDO;
    }

    /**
     *  dao层DO转mysql实体 定制奖励附件
     *
     * @param awardAwardDO
     * @return
     */
    public static List<AwardCustomAttachmentEntity> awardAwardDOToAwardCustomAttachmentEntity(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null || awardAwardDO.getPage() == null || CollectionUtils.isEmpty(awardAwardDO.getPage().getAttachments())) {
            return null;
        }
        List<AwardCustomAttachmentEntity> attachmentEntityList = awardAwardDO.getPage().getAttachments().stream().map(attachment -> {
            AwardCustomAttachmentEntity attachmentEntity = new AwardCustomAttachmentEntity();
            attachmentEntity.setAwardId(awardAwardDO.getId());
            attachmentEntity.setAttachmentId(attachment.getId());
            attachmentEntity.setName(attachment.getFileName());
            attachmentEntity.setUrl(attachment.getFilePath());
            return attachmentEntity;
        }).collect(Collectors.toList());
        return attachmentEntityList;
    }

    /**
     * dao层mysql实体转DO 定制奖励附件奖励信息
     *
     * @param attachmentEntityList
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardCustomAttachmentEntityToAwardAwardDO(List<AwardCustomAttachmentEntity> attachmentEntityList, AwardAwardDO awardAwardDO) {
        if (CollectionUtils.isEmpty(attachmentEntityList)) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(attachmentEntityList.get(0).getAwardId());
        List<AwardAwardDO.Attachment> attachmentList = attachmentEntityList.stream().map(attachmentEntity -> {
            AwardAwardDO.Attachment attachment = new AwardAwardDO.Attachment();
            attachment.setId(attachmentEntity.getAwardId());
            attachment.setFileName(attachmentEntity.getName());
            attachment.setFilePath(attachmentEntity.getUrl());
            return attachment;
        }).collect(Collectors.toList());
        if (awardAwardDO.getPage() == null) {
            awardAwardDO.setPage(new AwardAwardDO.Page());
        }
        awardAwardDO.getPage().setAttachments(attachmentList);
        return awardAwardDO;
    }

    /**
     * dao层DO转mysql实体 抽奖奖励
     *
     * @param awardAwardDO
     * @return
     */
    public static AwardDrawEntity awardAwardDOToAwardDrawEntity(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null) {
            return null;
        }
        Optional<AwardAwardDO> optional = Optional.of(awardAwardDO);
        AwardDrawEntity awardDrawEntity = new AwardDrawEntity();
        awardDrawEntity.setAwardId(awardAwardDO.getId());
        awardDrawEntity.setTotalCount(optional.map(AwardAwardDO::getBasic).map(AwardAwardDO.Basic::getTotalCount).orElse(null));
        awardDrawEntity.setStopAward(EnumUtil.booleanToInt(optional.map(AwardAwardDO::getRule).map(AwardAwardDO.Rule::getStopAward).orElse(null)));
        awardDrawEntity.setIssueType(optional.map(AwardAwardDO::getIssue).map(AwardAwardDO.Issue::getMethod).orElse(null));
        awardDrawEntity.setPrefix(optional.map(AwardAwardDO::getIssue).map(AwardAwardDO.Issue::getPrefix).orElse(null));
        awardDrawEntity.setTip(optional.map(AwardAwardDO::getIssue).map(AwardAwardDO.Issue::getTip).orElse(null));
        awardDrawEntity.setSmsContent(optional.map(AwardAwardDO::getIssue).map(AwardAwardDO.Issue::getSms).orElse(null));
        awardDrawEntity.setTemplateId(optional.map(AwardAwardDO::getIssue).map(AwardAwardDO.Issue::getTemplateId).orElse(null));
        awardDrawEntity.setTemplateTitle(optional.map(AwardAwardDO::getIssue).map(AwardAwardDO.Issue::getTemplateTitle).orElse(null));
        return awardDrawEntity;
    }

    /**
     * dao层mysql实体转DO 抽奖奖励
     *
     * @param awardDrawEntity
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardDrawEntityToAwardAwardDO(AwardDrawEntity awardDrawEntity, AwardAwardDO awardAwardDO) {
        if (awardDrawEntity == null) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(awardDrawEntity.getAwardId());
        if (awardAwardDO.getBasic() == null) {
            awardAwardDO.setBasic(new AwardAwardDO.Basic());
        }
        awardAwardDO.getBasic().setTotalCount(awardDrawEntity.getTotalCount());
        if (awardAwardDO.getRule() == null) {
            awardAwardDO.setRule(new AwardAwardDO.Rule());
        }
        awardAwardDO.getRule().setStopAward(EnumUtil.intToBoolean(awardDrawEntity.getStopAward()));
        if (awardAwardDO.getIssue() == null) {
            awardAwardDO.setIssue(new AwardAwardDO.Issue());
        }
        awardAwardDO.getIssue().setMethod(awardDrawEntity.getIssueType());
        awardAwardDO.getIssue().setPrefix(awardDrawEntity.getPrefix());
        awardAwardDO.getIssue().setTip(awardDrawEntity.getTip());
        awardAwardDO.getIssue().setSms(awardDrawEntity.getSmsContent());
        awardAwardDO.getIssue().setTemplateId(awardDrawEntity.getTemplateId());
        awardAwardDO.getIssue().setTemplateTitle(awardDrawEntity.getTemplateTitle());
        return awardAwardDO;
    }

    /**
     *  dao层DO转mysql实体 抽奖奖励奖项
     *
     * @param awardAwardDO
     * @return
     */
    public static List<AwardDrawAwardEntity> awardAwardDOToAwardDrawAwardEntity(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null || CollectionUtils.isEmpty(awardAwardDO.getAwards())) {
            return null;
        }
        List<AwardDrawAwardEntity> drawAwardEntityList = new ArrayList<>();
        for (int i = 0; i < awardAwardDO.getAwards().size(); i++) {
            AwardAwardDO.Award award = awardAwardDO.getAwards().get(i);
            AwardDrawAwardEntity awardEntity = new AwardDrawAwardEntity();
            awardEntity.setAwardId(awardAwardDO.getId());
            awardEntity.setIndex(i);
            awardEntity.setLevel(award.getLevel());
            awardEntity.setName(award.getName());
            awardEntity.setDesc(award.getDesc());
            awardEntity.setProbability(award.getProb());
            awardEntity.setImgUrl(award.getImg());
            awardEntity.setNum(award.getNum());
            awardEntity.setIssueType(award.getMethod());
            awardEntity.setPrefix(award.getPrefix());
            awardEntity.setTip(award.getTip());
            awardEntity.setLevelName(award.getLevelStr());
            drawAwardEntityList.add(awardEntity);
        }

        return drawAwardEntityList;
    }

    /**
     * dao层mysql实体转DO 抽奖奖励奖项
     *
     * @param drawAwardEntityList
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardDrawAwardEntityToAwardAwardDO(List<AwardDrawAwardEntity> drawAwardEntityList, AwardAwardDO awardAwardDO) {
        if (CollectionUtils.isEmpty(drawAwardEntityList)) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(drawAwardEntityList.get(0).getAwardId());
        Collections.sort(drawAwardEntityList, Comparator.comparingInt(AwardDrawAwardEntity::getIndex));
        List<AwardAwardDO.Award> awardList = new ArrayList<>();
        for (int i = 0; i < drawAwardEntityList.size(); i++) {
            AwardAwardDO.Award award = new AwardAwardDO.Award();
            AwardDrawAwardEntity awardEntity = drawAwardEntityList.get(i);
            award.setLevel(awardEntity.getLevel());
            award.setName(awardEntity.getName());
            award.setDesc(awardEntity.getDesc());
            award.setProb(awardEntity.getProbability());
            award.setImg(awardEntity.getImgUrl());
            award.setNum(awardEntity.getNum());
            award.setMethod(awardEntity.getIssueType());
            award.setPrefix(awardEntity.getPrefix());
            award.setTip(awardEntity.getTip());
            award.setLevelStr(awardEntity.getLevelName());
            awardList.add(award);
        }
        awardAwardDO.setAwards(awardList);
        return awardAwardDO;
    }

    /**
     * dao层DO转mysql实体 红包奖项
     *
     * @param awardAwardDO
     * @return
     */
    public static AwardRedPacketEntity awardAwardDOToAwardRedPacketEntity(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null) {
            return null;
        }
        Optional<AwardAwardDO> optional = Optional.of(awardAwardDO);
        AwardRedPacketEntity redPacketEntity = new AwardRedPacketEntity();
        redPacketEntity.setAwardId(awardAwardDO.getId());
        redPacketEntity.setName(optional.map(AwardAwardDO::getBasic).map(AwardAwardDO.Basic::getName).orElse(null));
        BigDecimal singleAmount = optional.map(AwardAwardDO::getBasic).map(AwardAwardDO.Basic::getSinAmount).orElse(null);
        if (singleAmount != null) {
            redPacketEntity.setSingleAmount(Math.toIntExact(MoneyUtil.yuanToCent(singleAmount)));
        }
        redPacketEntity.setTotalCount(optional.map(AwardAwardDO::getBasic).map(AwardAwardDO.Basic::getTotalCount).orElse(null));
        BigDecimal totalAmount = optional.map(AwardAwardDO::getBasic).map(AwardAwardDO.Basic::getTotalAmount).orElse(null);
        if (totalAmount != null) {
            redPacketEntity.setTotalAmount(Math.toIntExact(MoneyUtil.yuanToCent(totalAmount)));
        }
        Long probability = optional.map(AwardAwardDO::getBasic).map(AwardAwardDO.Basic::getProbability).orElse(null);
        if (probability != null) {
            redPacketEntity.setProbability(Math.toIntExact(probability));
        }
        redPacketEntity.setDisplayName(optional.map(AwardAwardDO::getBasic).map(AwardAwardDO.Basic::getDisplayName).orElse(null));
        redPacketEntity.setDisplayLogoId(optional.map(AwardAwardDO::getBasic).map(AwardAwardDO.Basic::getDisplayLogoId).orElse(null));
        redPacketEntity.setDisplayLogoPath(optional.map(AwardAwardDO::getBasic).map(AwardAwardDO.Basic::getDisplayLogoPath).orElse(null));
        redPacketEntity.setActivityId(awardAwardDO.getActivityId());
        redPacketEntity.setSettlementStatus(awardAwardDO.getSettlement());
        return redPacketEntity;
    }

    /**
     * dao层mysql实体转DO 红包奖项
     *
     * @param redPacketEntity
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardRedPacketEntityToAwardAwardDO(AwardRedPacketEntity redPacketEntity, AwardAwardDO awardAwardDO) {
        if (redPacketEntity == null) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(redPacketEntity.getAwardId());
        if (awardAwardDO.getBasic() == null) {
            awardAwardDO.setBasic(new AwardAwardDO.Basic());
        }
        awardAwardDO.getBasic().setName(redPacketEntity.getName());
        awardAwardDO.getBasic().setSinAmount(MoneyUtil.centToYuan(redPacketEntity.getSingleAmount()));
        awardAwardDO.getBasic().setTotalCount(redPacketEntity.getTotalCount());
        awardAwardDO.getBasic().setTotalAmount(MoneyUtil.centToYuan(redPacketEntity.getTotalAmount()));
        awardAwardDO.getBasic().setProbability(redPacketEntity.getProbability() == null ? null : Long.valueOf(redPacketEntity.getProbability()));
        awardAwardDO.getBasic().setDisplayName(redPacketEntity.getDisplayName());
        awardAwardDO.getBasic().setDisplayLogoId(redPacketEntity.getDisplayLogoId());
        awardAwardDO.getBasic().setDisplayLogoPath(redPacketEntity.getDisplayLogoPath());
        awardAwardDO.setActivityId(redPacketEntity.getActivityId());
        awardAwardDO.setSettlement(redPacketEntity.getSettlementStatus());

        return awardAwardDO;
    }

    /**
     * dao层DO转mysql实体 奖项规则
     *
     * @param awardAwardDO
     * @return
     */
    public static AwardRuleEntity awardAwardDOToAwardRuleEntity(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null || awardAwardDO.getRule() == null) {
            return null;
        }
        AwardRuleEntity ruleEntity = new AwardRuleEntity();
        AwardAwardDO.Rule rule = awardAwardDO.getRule();
        ruleEntity.setAwardId(awardAwardDO.getId());
        ruleEntity.setTime(rule.getTime());
        ruleEntity.setDrawPhone(rule.getDraw());
        ruleEntity.setWinPhone(rule.getWin());
        ruleEntity.setWinWechat(rule.getWin());
        ruleEntity.setAccount(rule.getAccount());
        ruleEntity.setDevice(rule.getDevice());
        ruleEntity.setIp(rule.getIp());
        ruleEntity.setDay(rule.getDay());
        ruleEntity.setScore(rule.getSscore() == null ? null : Long.valueOf(rule.getSscore()));

        return ruleEntity;
    }

    /**
     * dao层mysql实体转DO 奖项规则
     *
     * @param ruleEntity
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardRuleEntityToAwardAwardDO(AwardRuleEntity ruleEntity, AwardAwardDO awardAwardDO) {
        if (ruleEntity == null) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(ruleEntity.getAwardId());
        if (awardAwardDO.getRule() == null) {
            awardAwardDO.setRule(new AwardAwardDO.Rule());
        }
        AwardAwardDO.Rule rule = awardAwardDO.getRule();

        rule.setTime(ruleEntity.getTime());
        rule.setDraw(ruleEntity.getDrawPhone());
        if (ruleEntity.getWinPhone() != null) {
            rule.setWin(ruleEntity.getWinPhone());
        } else if (ruleEntity.getWinWechat() != null) {
            rule.setWin(ruleEntity.getWinWechat());
        }
        rule.setAccount(ruleEntity.getAccount());
        rule.setDevice(ruleEntity.getDevice());
        rule.setIp(ruleEntity.getIp());
        rule.setDay(ruleEntity.getDay());
        rule.setSscore(ruleEntity.getScore() == null ? null : Math.toIntExact(ruleEntity.getScore()));

        return awardAwardDO;
    }

    /**
     * dao层DO转mysql实体 第三方奖励
     *
     * @param awardAwardDO
     * @return
     */
    public static AwardThirdPartyEntity awardAwardDOToAwardThirdPartyEntity(AwardAwardDO awardAwardDO) {
        if (awardAwardDO == null || awardAwardDO.getPage() == null) {
            return null;
        }
        AwardThirdPartyEntity thirdPartyEntity = new AwardThirdPartyEntity();
        thirdPartyEntity.setAwardId(awardAwardDO.getId());
        thirdPartyEntity.setUrl(awardAwardDO.getPage().getUrl());
        return thirdPartyEntity;
    }

    /**
     * dao层mysql实体转DO 第三方奖励
     *
     * @param thirdPartyEntity
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardThirdPartyEntityToAwardAwardDO(AwardThirdPartyEntity thirdPartyEntity, AwardAwardDO awardAwardDO) {
        if (thirdPartyEntity == null) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(thirdPartyEntity.getAwardId());
        if (awardAwardDO.getPage() == null) {
            awardAwardDO.setPage(new AwardAwardDO.Page());
        }
        awardAwardDO.getPage().setUrl(thirdPartyEntity.getUrl());

        return awardAwardDO;
    }

    /**
     * dao层DO转mysql实体 卡券页面设置
     *
     * @param awardAwardDO
     * @return
     */
    public static List<AwardVoucherEntity> awardAwardDOToAwardVoucherEntity(AwardAwardDO awardAwardDO) {
        Optional<AwardAwardDO> optional = Optional.of(awardAwardDO);
        if (optional.map(AwardAwardDO::getPage).map(AwardAwardDO.Page::getMobile).orElse(null) == null && optional.map(AwardAwardDO::getPage).map(AwardAwardDO.Page::getPc).orElse(null) == null) {
            return null;
        }
        List<AwardVoucherEntity> awardVoucherEntityList = new ArrayList<>();
        Optional<AwardAwardDO.PageFront> phone = optional.map(AwardAwardDO::getPage).map(AwardAwardDO.Page::getMobile);
        AwardVoucherEntity phoneEntity = awardAwardDOPageFrontToAwardVoucherEntity(phone);
        if (phoneEntity != null) {
            phoneEntity.setAwardId(awardAwardDO.getId());
            phoneEntity.setDeviceType(DeviceTypeEnum.MOBILE.getIndex());
            awardVoucherEntityList.add(phoneEntity);
        }
        Optional<AwardAwardDO.PageFront> pc = optional.map(AwardAwardDO::getPage).map(AwardAwardDO.Page::getPc);
        AwardVoucherEntity pcEntity = awardAwardDOPageFrontToAwardVoucherEntity(pc);
        if (pcEntity != null) {
            pcEntity.setAwardId(awardAwardDO.getId());
            pcEntity.setDeviceType(DeviceTypeEnum.PC.getIndex());
            awardVoucherEntityList.add(pcEntity);
        }
        return awardVoucherEntityList;
    }

    /**
     * dao层DO转mysql实体 卡券页面设置
     *
     * @param optional
     * @return
     */
    public static AwardVoucherEntity awardAwardDOPageFrontToAwardVoucherEntity(Optional<AwardAwardDO.PageFront> optional) {
        if (optional.orElse(null) == null) {
            return null;
        }
        AwardVoucherEntity awardVoucherEntity = new AwardVoucherEntity();
        awardVoucherEntity.setTitle(optional.map(AwardAwardDO.PageFront::getTitle).orElse(null));
        awardVoucherEntity.setTip(optional.map(AwardAwardDO.PageFront::getText).map(AwardAwardDO.PageFrontText::getData).orElse(null));
        awardVoucherEntity.setBackgroundColor(optional.map(AwardAwardDO.PageFront::getBg).map(AwardAwardDO.PageFrontBg::getColor).orElse(null));
        awardVoucherEntity.setBackgroundId(optional.map(AwardAwardDO.PageFront::getBg).map(AwardAwardDO.PageFrontBg::getId).orElse(null));
        awardVoucherEntity.setBackgroundPath(optional.map(AwardAwardDO.PageFront::getBg).map(AwardAwardDO.PageFrontBg::getPath).orElse(null));
        awardVoucherEntity.setQrCodeId(optional.map(AwardAwardDO.PageFront::getQr).map(AwardAwardDO.PageFrontQr::getId).orElse(null));
        awardVoucherEntity.setQrCodePath(optional.map(AwardAwardDO.PageFront::getQr).map(AwardAwardDO.PageFrontQr::getPath).orElse(null));
        awardVoucherEntity.setLogoId(optional.map(AwardAwardDO.PageFront::getLogo).map(AwardAwardDO.PageFrontLogo::getId).orElse(null));
        awardVoucherEntity.setLogoPath(optional.map(AwardAwardDO.PageFront::getLogo).map(AwardAwardDO.PageFrontLogo::getPath).orElse(null));
        awardVoucherEntity.setLogoScale(optional.map(AwardAwardDO.PageFront::getLogo).map(AwardAwardDO.PageFrontLogo::getScale).orElse(null));
        awardVoucherEntity.setLogoPosition(optional.map(AwardAwardDO.PageFront::getLogo).map(AwardAwardDO.PageFrontLogo::getPos).orElse(null));
        return awardVoucherEntity;
    }

    /**
     * dao层mysql实体转DO 卡券页面设置
     *
     * @param awardVoucherEntityList
     * @param awardAwardDO
     * @return
     */
    public static AwardAwardDO awardVoucherEntityToAwardAwardDO(List<AwardVoucherEntity> awardVoucherEntityList, AwardAwardDO awardAwardDO) {
        if (CollectionUtils.isEmpty(awardVoucherEntityList)) {
            return awardAwardDO;
        }
        if (awardAwardDO == null) {
            awardAwardDO = new AwardAwardDO();
        }
        awardAwardDO.setId(awardVoucherEntityList.get(0).getAwardId());
        if (awardAwardDO.getPage() == null) {
            awardAwardDO.setPage(new AwardAwardDO.Page());
        }
        for (AwardVoucherEntity voucherEntity : awardVoucherEntityList) {
            AwardAwardDO.PageFront pageFront = awardVoucherEntityToAwardAwardDOPageFront(voucherEntity);
            if (pageFront != null) {
                if (Objects.equals(voucherEntity.getDeviceType(), DeviceTypeEnum.MOBILE.getIndex())) {
                    awardAwardDO.getPage().setMobile(pageFront);
                } else if (Objects.equals(voucherEntity.getDeviceType(), DeviceTypeEnum.PC.getIndex())) {
                    awardAwardDO.getPage().setPc(pageFront);
                }
            }
        }
        return awardAwardDO;
    }

    /**
     * dao层mysql实体转DO 卡券页面设置
     *
     * @param awardVoucherEntity
     * @return
     */
    public static AwardAwardDO.PageFront awardVoucherEntityToAwardAwardDOPageFront(AwardVoucherEntity awardVoucherEntity) {
        if (awardVoucherEntity == null) {
            return null;
        }
        AwardAwardDO.PageFront pageFront = new AwardAwardDO.PageFront();
        pageFront.setTitle(awardVoucherEntity.getTitle());

        AwardAwardDO.PageFrontText pageFrontText = new AwardAwardDO.PageFrontText();
        pageFrontText.setData(awardVoucherEntity.getTip());
        pageFront.setText(pageFrontText);

        AwardAwardDO.PageFrontBg bg = new AwardAwardDO.PageFrontBg();
        bg.setColor(awardVoucherEntity.getBackgroundColor());
        bg.setId(awardVoucherEntity.getBackgroundId());
        bg.setPath(awardVoucherEntity.getBackgroundPath());
        pageFront.setBg(bg);

        AwardAwardDO.PageFrontQr qr = new AwardAwardDO.PageFrontQr();
        qr.setId(awardVoucherEntity.getQrCodeId());
        qr.setPath(awardVoucherEntity.getQrCodePath());
        pageFront.setQr(qr);

        AwardAwardDO.PageFrontLogo logo = new AwardAwardDO.PageFrontLogo();
        logo.setId(awardVoucherEntity.getLogoId());
        logo.setPath(awardVoucherEntity.getLogoPath());
        logo.setScale(awardVoucherEntity.getLogoScale());
        logo.setPos(awardVoucherEntity.getLogoPosition());
        pageFront.setLogo(logo);

        return pageFront;
    }

}
